package com.operation;

import java.io.IOException;

import com.control.DocManager;
import com.control.JDBManager;
import com.control.KeywordManager;

public class Indexer {

	public static void main(String[] args) {

		JDBManager dbManager = null;
		try {
			dbManager = new JDBManager("cseDB");
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println("initialize db successfully");

		DocManager docManager = new DocManager();
		docManager.initializeDocs("http://www.cs.ust.hk/", 30);
		System.out.println("initialize docs successfully");

		KeywordManager keywordManager = new KeywordManager();
		keywordManager.indexKeywords(docManager.getUrls(), dbManager);
		System.out.println("index keywords successfully");

		docManager.buildDocIndex(keywordManager.getDocSize(),
				keywordManager.getMax_tf(), keywordManager.getWordsForDocs(),
				dbManager);
		System.out.println("index docs successfully");

		try {
			dbManager.commit();
			dbManager.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("finish");

	}
}
